package zhongbo.java.air.monitor.web;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
import zhongbo.java.air.common.exception.MyException;
import zhongbo.java.air.common.vo.PageVo;
import zhongbo.java.air.common.vo.ResultVo;
import zhongbo.java.air.monitor.model.AirAlertLog;
import zhongbo.java.air.monitor.model.FlightActivityDaily;
import zhongbo.java.air.monitor.service.IFlightActivityDailyService;

import java.util.List;

/**
 * 说明：
 *
 * @author 钟波dellNotebook
 * @since 2025年04月08日 星期二 03:35:26
 */
@RestController
@RequestMapping("flightActivityDaily")
@Api(tags = "每日航迹活动信息接口")
public class FlightActivityDailyController {
    @Qualifier("flightActivityDailyServiceImpl")
    @Autowired
    private IFlightActivityDailyService flightActivityDailyService;

    @ApiOperation("查询当天分组统计结果")
    @GetMapping("getDailyStats")
    public ResultVo<List<FlightActivityDaily>> getDailyStats(String date) {
        // 如果不传, 则默认查当天的统计结果
        if (StrUtil.isBlank(date)) {
            date = DateUtil.today();
        }
        List<FlightActivityDaily> dailyList = flightActivityDailyService.getDailyStats(date);
        return ResultVo.ok(dailyList);
    }

    @PostMapping("add")
    @ApiOperation("增加记录")
    public ResultVo<FlightActivityDaily> addFlightActivityDaily(@RequestBody FlightActivityDaily flightActivityDaily) {
        try {
         FlightActivityDaily flightActivityDaily1 =  flightActivityDailyService.addFlightActivityDaily(flightActivityDaily);
            return ResultVo.ok(flightActivityDaily1);
        } catch (MyException e) {
            return ResultVo.error(e.getMessage());
        }
    }
    @PostMapping("edit")
    @ApiOperation("修改")
    public ResultVo<FlightActivityDaily> updateFlightActivityDaily(@RequestBody FlightActivityDaily flightActivityDaily) {
        try {
          FlightActivityDaily flightActivityDaily1 = flightActivityDailyService.updateFlightActivityDaily(flightActivityDaily);
            return ResultVo.ok(flightActivityDaily1);
        }catch (MyException e){
            return ResultVo.error(e.getMessage());
        }
    }
    @GetMapping("delete")
    @ApiOperation("删除记录")
    public ResultVo<String> deleteFlightActivityDaily(@RequestParam int id) {
        try {
            flightActivityDailyService.deleteFlightActivityDaily(id);
            return ResultVo.ok("1");

        }catch (MyException e){
            return ResultVo.error(e.getMessage());
        }
    }
    @PostMapping("findOne")
    @ApiOperation("查询记录")
    public ResultVo<FlightActivityDaily> selectFlightActivityDaily(@RequestParam String Id) {
        try {
           FlightActivityDaily flightActivityDaily= flightActivityDailyService.selectFlightActivityDaily(Id);
            return ResultVo.ok(flightActivityDaily);
        }catch (MyException e){
            return ResultVo.error(e.getMessage());
        }
    }

//    @GetMapping("findPage")
//    @ApiOperation("分页查询列表")
//    public ResultVo<PageVo<FlightActivityDaily>> page(Integer pageNumber, Integer pageSize, boolean order, String searchField, String keyword, String sortField){
//        PageVo<FlightActivityDaily> page =flightActivityDailyService.page( pageNumber, pageSize,order, searchField, keyword, sortField);
//        return ResultVo.ok (page);
//    }
    @GetMapping("findPage")
    @ApiOperation("分页查询2")
    public ResultVo<PageVo<FlightActivityDaily>> pageByIcaoCode(
            @RequestParam(defaultValue = "1") Integer pageNumber,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) String icaoCode,
            @RequestParam(required = false)
            String startTime,
            @RequestParam(required = false)
            String endTime,
            @RequestParam
            String oderByField,
            @RequestParam
            boolean orderByAsc,
            @RequestParam
            String searchField,
            @RequestParam
            String keyword
    ) {

        try {
            PageVo<FlightActivityDaily> page = flightActivityDailyService.pageByIcaoCode(pageNumber, pageSize, icaoCode, startTime, endTime, oderByField, orderByAsc,searchField,  keyword);
            return ResultVo.ok(page);
        } catch (MyException e) {
            return ResultVo.error(e.getMessage());
        }
    }
}
